﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using OMOMLibrary.Generator;
using OMOMLibrary.Grid;
using OMOMLibrary.Grid.Terrains;

namespace OMOMViewer
{
    public partial class GridDrawer : UserControl
    {
        private Grid grid;

        private Position pos;

        public GridDrawer()
        {
            InitializeComponent();
            Paint += new PaintEventHandler(GridDrawer_Paint);
            pos = new Position(0, 0);
            Generator g = new Generator(100,100);
            grid = g.generateGrid();
        }

        public GridDrawer(Grid g) : base(){
            grid = g;
            
        }

        private int getHorizontalCells() 
        {
            return (int)Math.Ceiling((double)Width / 20);
        }

        private int getVerticalCells()
        {
            return (int)Math.Ceiling((double)Height / 20);
        }

        void GridDrawer_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Mountain m = new Mountain();
            int i,j;
            for (i = 0; i < getVerticalCells(); i++)
            {
                for (j = 0; j < getHorizontalCells(); j++)
                {
                    Cell c = grid.Cells[pos.X + j, pos.Y + i];
                    g.DrawImage(c.Terrain.Img, i * 20, j * 20);

                }
            }
            
        }
    }
}
